// 商品模块 {state,mutations,actions}

// 导入api获取导航栏内容
import { findAllCategoryAPI } from '@/api/category'
// 导入导航栏常量数据(处理请求api时,2.5s的请求过程导致的导航栏白屏)
import { topCategory } from '@/api/constant.js'

export default {
  // 彻底分离模块
  namespaced: true,
  state() {
    return {
      // 存商品分类的
      list: topCategory.map(item => ({ name: item })),
    };
  },

  mutations: {
    setList(state, headCategory) {
      state.list = headCategory
    }
  },

  actions: {
    async getList(stx) {
      const { result } = await findAllCategoryAPI()
      // console.log(result);
      stx.commit('setList', result)
    }
  }
};
